﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SiteAgle.Models
{
    public class DaoComentario
    {
        /// <summary>
        /// Salvars the specified tarefa.
        /// </summary>
        /// <param name="tarefa">The tarefa.</param>
        public void Salvar(Comentarios comentario)
        {
            AgleEntities tmp = DataAccessSingleton.Entities;

            if (comentario.Id > 0)
            {

            }
            else
            {
                // tmp.Attach(tarefa);
                // tmp.CreateEntityKey("Tarefa", tarefa);
                // tmp.SaveChanges();
                DataAccessSingleton.Entities.AddToComentarios(comentario);
                //DataAccessSingleton.Entities.Attach(tarefa);
                //DataAccessSingleton.Entities.CreateEntityKey("Tarefa", tarefa);
                //
            }
            //            DataAccessSingleton.Entities.AcceptAllChanges();
            DataAccessSingleton.Entities.SaveChanges();
        }

        /// <summary>
        /// Obters the por ID.
        /// </summary>
        /// <param name="ID">The ID.</param>
        /// <returns></returns>
        public Comentarios ObterPorID(int ID)
        {
            return DataAccessSingleton.Entities.Comentarios.Where(g => g.Id.Equals(ID)).FirstOrDefault();
        }


     


        /// <summary>
        /// Listars this instance.
        /// </summary>
        /// <returns></returns>
        public IList<Comentarios> listarPorTarefa(int idTarefa)
        {
            return DataAccessSingleton.Entities.Comentarios.Where(c=>c.IdTarefa == idTarefa).ToList();
        }
        public int TotallistarPorTarefa(int idTarefa)
        {
            return DataAccessSingleton.Entities.Comentarios.Where(c => c.IdTarefa == idTarefa).Count();
        }
        public int TotallistarPorTarefaNaoLidas(int idTarefa)
        {
            return DataAccessSingleton.Entities.Comentarios.Where(c => c.IdTarefa == idTarefa && c.Lido == false).Count();
        }
        /// <summary>
        /// Excluirs the specified tarefa.
        /// </summary>
        /// <param name="tarefa">The tarefa.</param>
        public void Excluir(Comentarios comentario)
        {
            DataAccessSingleton.Entities.Comentarios.DeleteObject(comentario);
            DataAccessSingleton.Entities.SaveChanges();
        }
      
    }
}